package org.rabbitmq.common.configuration;

import org.rabbitmq.common.enums.ExchangeEnum;
import org.rabbitmq.common.enums.QueueEnum;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author LSY Time: 2018年12月6日上午10:40:07
 *
 *
 */
@Configuration
public class UserRegisterQueueConfiguration {

	/**
	 * 配置路由交换对象实例
	 * @return
	 */
	@Bean
	public DirectExchange userRegisterQueueExchange() {
		return new DirectExchange(ExchangeEnum.USER_REGISTER.getValue());
	}

	/**
	 * 配置用户注册对象实例
	 *  并设置持久化队列
	 * @return
	 */
	@Bean
	public Queue userRegisterQueue() {
		return new Queue(QueueEnum.USER_REGISTER.getName(), true);
	}

	/**
	 * 将用户注册队列绑定到路由交换配置上并配置指定路由键将进行转发
	 * @return
	 */
	@Bean
	public Binding userRegisterBinding() {
		return BindingBuilder.bind(userRegisterQueue()).to(userRegisterQueueExchange())
				.with(QueueEnum.USER_REGISTER.getRoutingKey());
	}
}
